package cc.htdf.gwc.observation.controller;

import cc.htdf.gwc.observation.domain.response.ResponseBody;
import cc.htdf.gwc.observation.domain.response.ResponseCode;
import cc.htdf.gwc.observation.service.ObserveDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by JT on 2017/10/11.
 */
@RestController
@RequestMapping("/data")
public class ObserveDataController {

    @Autowired
    private ObserveDataService observeDataService;

    @GetMapping("/ChengDu")
    @CrossOrigin
    public ResponseBody fetchChengDuObserveDataByStationsAndDate(@RequestParam("stations") String stations,
                                                         @RequestParam("date") String date,
                                                         @RequestParam("elements") String elements) {
        List<Map<String, Object>> list = observeDataService.fetchObserveDateByStationsAndDate(stations, date, elements);
        return new ResponseBody(ResponseCode.STATUS_SUCCESS, "数据获取成功！", list);
    }

    @GetMapping("/Score")
    @CrossOrigin
    public ResponseBody observeData(@RequestParam("stations") String stations,
                                    @RequestParam("startDate") String startDate,
                                    @RequestParam("endDate") String endDate,
                                    @RequestParam("elements") String elements) {
        List<Map<String, Object>> list = observeDataService.observeDate(stations, startDate,endDate, elements);
        return new ResponseBody(ResponseCode.STATUS_SUCCESS, "数据获取成功！", list);
    }


    @GetMapping("/ChengDu/{station}")
    @CrossOrigin
    public ResponseBody fetchChengDuObserveDataByStationId(@PathVariable("station") String station,
                                    @RequestParam("elements") String elements) {
        List<Map<String, Object>> list = observeDataService.fetchChengDuObserveDataByStationId(station,elements);
        return new ResponseBody(ResponseCode.STATUS_SUCCESS, "数据获取成功！", list);
    }

}
